package mapapp;

import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Point2D;
import org.jdesktop.swingx.JXMapViewer;
import org.jdesktop.swingx.mapviewer.GeoPosition;


public class Coordonate {
	double pixelOx;
	double pixelOy;
	
	public double getPixelOx() {
		return pixelOx;
	}
	public void setPixelOx(double pixelOx) {
		this.pixelOx = pixelOx;
	}
	public double getPixelOy() {
		return pixelOy;
	}
	public void setPixelOy(double pixelOy) {
		this.pixelOy = pixelOy;
	}
	
	public Coordonate(){
		this.pixelOx=0;
		this.pixelOy=0;
	}
	public Coordonate(double pX,double pY){
		this.pixelOx=pX;
		this.pixelOy=pY;
	}
	public Point convertToPixel(double latitude,double longitude){
                 MapApp app=MapApp.getApplication();
                 MapView mapV=(MapView) app.getMainView();
		 JXMapViewer map = mapV.getMapKit().getMainMap();
                 GeoPosition gp = new GeoPosition(latitude,longitude);
                 //convert to world bitmap
                 Point2D gp_pt = map.getTileFactory().geoToPixel(gp, map.getZoom());
                 Rectangle rect = map.getViewportBounds();
                 Point converted_gp_pt = new Point((int)gp_pt.getX()-rect.x,
                                          (int)gp_pt.getY()-rect.y);
                 return converted_gp_pt;
	}

}
